#! /bin/sh

source /etc/rc.d/common

CLVMD="/usr/sbin/clvmd"
CLVMD_LOCK="/var/lock/clvmd"
DFLT_OPTS="-T10"

check_args ${@}

SCRIPT="$(/usr/bin/basename ${0})"
if check_opts_set ${SCRIPT}; then
    USER_OPTS="$(get_rc_opts ${SCRIPT})"
    if [ ${?} -ne 0 ]; then
        /bin/echo ${USER_OPTS}
        exit 1
    fi
else
    USER_OPTS="${DFLT_OPTS}"
fi

start() {
    /bin/echo "Starting clvmd..."
    eval ${CLVMD} ${USER_OPTS}
    exit_val=${?}
    if [ ${exit_val} -ne 0 -a ${exit_val} -ne 5 ]; then
        exit 1
    fi
    /bin/touch ${CLVMD_LOCK}
}

stop() {
    /bin/echo "Stopping clvmd..."
    /bin/kill -TERM $(/bin/pidof ${CLVMD}) || exit 1
    wait_for_stop ${CLVMD} && /bin/rm -f ${CLVMD_LOCK}
}

status() {
    /bin/pidof ${CLVMD} > /dev/null 2>&1
    exit ${?}
}

# Perform specified action
${1}
